import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_layout/app.dart';
import 'package:flutter_layout/base/routes.dart';
import 'package:flutter_layout/data/event_task_bean.dart';
import 'package:flutter_layout/main/base_stateful_widget.dart';
import 'package:flutter_layout/pages/align/align_page.dart';
import 'package:flutter_layout/pages/anim/anim_page.dart';
import 'package:flutter_layout/pages/appbar/appbar_page.dart';
import 'package:flutter_layout/pages/bottom/bottom_page.dart';
import 'package:flutter_layout/pages/button/button_page.dart';
import 'package:flutter_layout/pages/canvas/canvas_page.dart';
import 'package:flutter_layout/pages/check/check_page.dart';
import 'package:flutter_layout/pages/clip/clip_page.dart';
import 'package:flutter_layout/pages/constrain/constrain_page.dart';
import 'package:flutter_layout/pages/custom/htextview.dart';
import 'package:flutter_layout/pages/custom/listview_page.dart';
import 'package:flutter_layout/pages/dialog/dialog_page.dart';
import 'package:flutter_layout/pages/downrefresh/rereshview_page.dart';
import 'package:flutter_layout/pages/element/ekement_page.dart';
import 'package:flutter_layout/pages/emaple/eample_page.dart';
import 'package:flutter_layout/pages/event/event_bus_page.dart';
import 'package:flutter_layout/pages/http/http_page.dart';
import 'package:flutter_layout/pages/layout/layout_page.dart';
import 'package:flutter_layout/pages/listview/reorderable_listView_page.dart';
import 'package:flutter_layout/pages/listview/switch_view_page.dart';
import 'package:flutter_layout/pages/loadding/load_page.dart';
import 'package:flutter_layout/pages/my/my_page.dart';
import 'package:flutter_layout/pages/noenable/no_enable_page.dart';
import 'package:flutter_layout/pages/otherpage/listener_page.dart';
import 'package:flutter_layout/pages/placeholder/placeholder_page.dart';
import 'package:flutter_layout/pages/pointers/pointer_page.dart';
import 'package:flutter_layout/pages/scroll/scroll_page.dart';
import 'package:flutter_layout/pages/scrollview/scrollview_page.dart';
import 'package:flutter_layout/pages/shape/shape_page.dart';
import 'package:flutter_layout/pages/spacer/spacerview_page.dart';
import 'package:flutter_layout/pages/splash_page.dart';
import 'package:flutter_layout/pages/text/text_page.dart';
import 'package:flutter_layout/pages/theme/theme_page.dart';
import 'package:flutter_layout/pages/view/view_page.dart';
import 'package:flutter_layout/pages/websocket/web_socket_page.dart';
import 'package:flutter_layout/wanandroid/wanandroid_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_layout/base/index.dart';

class HomePage extends BaseStatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _isChangeTheme = false;
  bool _isChangeLanuage = false;

  var listData = <String>[];

  @override
  void initState() {
    App.homeStatus = true;
    super.initState();
  }

  @override
  void deactivate() {
    super.deactivate();
  }

  @override
  void dispose() {
    App.homeStatus = false;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //设置尺寸（填写设计中设备的屏幕尺寸）如果设计基于360dp * 690dp的屏幕
    ScreenUtil.init(
        BoxConstraints(maxWidth: MediaQuery.of(context).size.width, maxHeight: MediaQuery.of(context).size.height),
        designSize: const Size(705, 1334),
        context: context,
        minTextAdapt: true,
        orientation: Orientation.portrait);
    return Scaffold(
      appBar: AppBar(),
      body: mainDemo(context),
    );
  }

  Widget mainDemo(BuildContext context) {
    var listData = <Widget>[
      ElevatedButton(
        child: const HTextView("SwitchTheme"),
        onPressed: () {
          _isChangeTheme = !_isChangeTheme;
          widget.showAppToast(_isChangeTheme.toString());
          if (!Get.isDarkMode) {
            Get.changeTheme(ThemeData.dark());
            // Get.changeThemeMode(ThemeMode.dark);
          } else {
            Get.changeTheme(ThemeData.light());
            // Get.changeThemeMode(ThemeMode.light);
          }

          // Get.changeTheme(!Get.isDarkMode
          //     ? ThemeData(
          //         brightness: Brightness.dark,
          //         primaryColor: Colors.yellow,
          //       )
          //     : ThemeData(
          //         brightness: Brightness.light,
          //         primaryColor: Colors.deepOrangeAccent,
          //       ));
        },
      ),
      ElevatedButton(
        child: const HTextView("SwitchLanuage"),
        onPressed: () {
          _isChangeLanuage = !_isChangeLanuage;
          if (_isChangeLanuage) {
            Get.updateLocale(const Locale('en', 'US'));
          } else {
            Get.updateLocale(const Locale('zh', 'CN'));
          }
          // Get.appUpdate();
        },
      ),
      ElevatedButton(
        child: const HTextView("HttpPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const HttpPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("完整App"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            // Android状态栏透明 splash为白色,所以调整状态栏文字为黑色
            SystemChrome.setSystemUIOverlayStyle(
                SystemUiOverlayStyle(statusBarColor: Colors.transparent, statusBarBrightness: Brightness.light));
            return const WanandroidPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("布局"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const LayoutPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("手势"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const PointerPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("文本"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const TextPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("事件流"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const WebSocketPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("选中效果"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const CheckPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("主题"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ThemePage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("底部导航"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const BottomPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("画布"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const CanvasPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("MyHomePage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const MyHomePage(title: '咸鱼');
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("NoFoundPage"),
        onPressed: () => Get.toNamed("/xx"),
      ),
      ElevatedButton(
        child: const HTextView("MyPage"),
        onPressed: () => Get.toNamed(Routes.my),
      ),
      ElevatedButton(
        child: const HTextView("MainPage"),
        // onPressed: () => Get.to(MainPage()),
        onPressed: () => Get.toNamed(Routes.main),
      ),
      ElevatedButton(
        child: const HTextView("DialogPage"),
        onPressed: () => Get.to(() => const DialogPage()),
      ),
      // ElevatedButton(
      //   child: HTextView("CustomWidget"),
      //   onPressed: () {
      //     Navigator.push(context, MaterialPageRoute(builder: (context) {
      //       return CustomWidget();
      //     }));
      //   },
      // ),
      ElevatedButton(
        child: const HTextView("AlignPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const AlignPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ButtonPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ButtonPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("NoEnablePage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const NoEnablePage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ListenerPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ListenerPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ClipPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ClipPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("LoadPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const LoadPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("RefreshPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const RefreshViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("AppbarPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const AppbarPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ConstrainPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ConstrainPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("SpacerViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const SpacerViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ElementPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ElementPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ScrollViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ScrollViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ScrollPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ScrollPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("MyPageView"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const MyPageView();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("EamplePage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const EamplePage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ListViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ListViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("SplashPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const SplashPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ShapePage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ShapePage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("EventBusPage"),
        onPressed: () {
          behaviorBus.fire(EventTaskBean(0, {"id": "我是传参的数据"}));
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const EventBusPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("SwitchViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const SwitchViewPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("PlaceholderPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const PlaceholderPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("AnimPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const AnimPage();
          }));
        },
      ),
      ElevatedButton(
        child: const HTextView("ReorderableListViewPage"),
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return const ReorderableListViewPage();
          }));
        },
      ),
    ];
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: ListView.builder(
          itemBuilder: (context, index) {
            return listData[index];
          },
          itemCount: listData.length),
    );
  }
}
